//    Copyright (C) 2008 Dirk Vanden Boer <dirk.vdb@gmail.com>
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#include "log.h"

#ifdef ENABLE_LOGGING
    #include <log4cpp/BasicLayout.hh>
#endif

namespace utils
{

using namespace std;

Log::Log(const string& filename)
{
#ifdef ENABLE_LOGGING
    m_pAppender = new log4cpp::FileAppender("lastfmliblog", filename);
    m_pAppender->setLayout(new log4cpp::BasicLayout());

    m_pRootCategory = &log4cpp::Category::getRoot();
    m_pRootCategory->setAdditivity(false);
    m_pRootCategory->addAppender(m_pAppender);
#endif
}

Log::~Log()
{
#ifdef ENABLE_LOGGING
    log4cpp::Category::shutdown();
#endif
}

void Log::error(const std::string& message)
{
#ifdef ENABLE_LOGGING
    m_pRootCategory->error(message);
#endif
}

void Log::info(const std::string& message)
{
#ifdef ENABLE_LOGGING
    m_pRootCategory->info(message);
#endif
}

}
